﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using ZG_member.Model;
using System.Configuration;

namespace ZG_member.DAL
{
    public class SQLsynchronization
    {
        static SqlConnection conn;

        public SQLsynchronization(string sql) {
            conn = new SqlConnection(sql);
        }
        //List<string> tablename = new List<string>();
        public List<string> Gettablename() {
            string sqlBytable = "select name from sysobjects where xtype='U'";
            SqlCommand cmd = new SqlCommand(sqlBytable, conn);
            List<string> name = new List<string>();
            conn.Open();
            SqlDataReader dr  = cmd.ExecuteReader();
            
            while (dr.Read())
            {
                name.Add(dr[0].ToString());
            }
            dr.Close();
            conn.Close();
            return name;
        }

        //获取积分之间的差值
        public void chazhi() {
            //string sql = ConfigurationManager.AppSettings["fuwuqi"];
            memberInfo mi = new memberInfo();
            //conn = new SqlConnection(sql);
            string sqlBymemberInfomodle = "select i.id,m.point,i.Userintegral,m.consume,i.consume from dbo.memberInfo m,integrallisting i where m.memberId =  '' and i.membercardID =''";
            SqlCommand cmd = new SqlCommand(sqlBymemberInfomodle, conn);
            List<Model.integral> intmod = new List<Model.integral>();
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                Model.integral i = new Model.integral();
                i.Id = int.Parse(dr["id"].ToString());
                i.Userintegral1 = (int.Parse(dr["m.point"].ToString()) - int.Parse(dr["i.point"].ToString())).ToString();
                i.Consume = (int.Parse(dr["m.consume"].ToString()) - int.Parse(dr["i.consume"].ToString())).ToString();
                i.MembercardID = dr["memberInfo"].ToString();
                intmod.Add(i);
            }
            dr.Close();
            conn.Close();
            
            if (intmod.Count<=0)
            {
                return;
            }
            string sql = ConfigurationManager.AppSettings["fuwuqi"];

            conn = new SqlConnection(sql);
            for (int i = 0; i < intmod.Count; i++)
            {
                mi.jifenUpdate(intmod[i].Userintegral1,intmod[i].Consume,intmod[i].MembercardID);
            }


        } 








        public void addjifen() {

           


            List<Model.memberInfo> memberInfomod = new List<Model.memberInfo>();
            memberInfo memberInfodal = new memberInfo();
            //amod = a.GetModelAll();
            string sqlBymemberInfomodle = "select id,memberId,memberCardId,memberName,sex,mobile,Tel,Email,IDNumber,birthDay,cardType,Balance,point,status,createDate,expiresDate,consume,memo,pwd,Marriage,Zip,Address,AreasID from dbo.memberInfo";
            SqlCommand cmd = new SqlCommand(sqlBymemberInfomodle, conn);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                Model.memberInfo amodle = new Model.memberInfo();
                amodle.id = int.Parse(dr["id"].ToString());
                amodle.memberId = dr["memberId"].ToString();
                amodle.memberCardId = dr["memberCardId"].ToString();
                amodle.memberName = dr["memberName"].ToString();
                amodle.sex = bool.Parse(dr["sex"].ToString());
                amodle.mobile = dr["mobile"].ToString();
                amodle.Tel = dr["Tel"].ToString();
                amodle.Email = dr["Email"].ToString();
                amodle.IDNumber = dr["IDNumber"].ToString();
                amodle.birthDay = DateTime.Parse(dr["birthDay"].ToString());
                amodle.cardType = int.Parse(dr["cardType"].ToString());
                amodle.Balance = decimal.Parse(dr["Balance"].ToString());
                amodle.point = int.Parse(dr["point"].ToString());
                amodle.status = int.Parse(dr["status"].ToString());
                amodle.createDate = DateTime.Parse(dr["createDate"].ToString());
                amodle.expiresDate = DateTime.Parse(dr["expiresDate"].ToString());
                amodle.consume = decimal.Parse(dr["consume"].ToString());
                amodle.memo = dr["memo"].ToString();
                amodle.pwd = dr["pwd"].ToString();
                amodle.Marriage = dr["Marriage"].ToString();
                amodle.Zip = dr["Zip"].ToString();
                amodle.Address = dr["Address"].ToString();
                amodle.AreasID = int.Parse(dr["AreasID"].ToString());
                memberInfomod.Add(amodle);
            }
            conn.Close();
            dr.Close();

            string sqldelete = string.Format("delete from integrallisting");
            cmd = new SqlCommand(sqldelete, conn);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

            if (memberInfomod.Count <= 0)
            {
                return;
            }
            for (int i = 0; i < memberInfomod.Count; i++)
            {

                string sqlesists = string.Format("select COUNT(*) from integrallisting where membercardID = '{0}'", memberInfomod[i].memberId);
                cmd = new SqlCommand(sqlesists,conn);    
                conn.Open();
                   int aaaa = (int)cmd.ExecuteScalar();
                    conn.Close();

                if (aaaa>0)
                {
                    string sqlupdate = string.Format("update dbo.integrallisting set Userintegral = '{0}' ,consume = '{1}' where membercardID = '{2}'", memberInfomod[i].point, memberInfomod[i].consume, memberInfomod[i].memberId);
                    cmd = new SqlCommand(sqlupdate, conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    
                }
                else
                {
                    string sqladd = string.Format("insert into dbo.integrallisting(Userintegral,consume,membercardID) values('{0}','{1}','{2}')", memberInfomod[i].point, memberInfomod[i].consume, memberInfomod[i].memberId);
                    cmd = new SqlCommand(sqladd, conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
        }



        public void synchronization(string SQltablename) {
            SqlCommand cmd;
            SqlDataReader dr;
            conn.Open();
            switch (SQltablename)
            {
                case "advInfo":
                    List<Model.advInfo> amod = new List<Model.advInfo>();
                    advInfo a = new advInfo();
                    //amod = a.GetModelAll();
                    string sqlByModle = "select id,advContent from dbo.advInfo";
                    cmd = new SqlCommand(sqlByModle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.advInfo amodle = new Model.advInfo();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.advContent = dr["advContent"].ToString();
                        amod.Add(amodle);
                    }
                    if (amod.Count<=0)
                    {
                        break;
                    }
                    for (int i = 0; i < amod.Count; i++)
                    {
                        if (a.Exists(amod[i].id, amod[i].advContent))
                        {
                            Model.advInfo amodles = new Model.advInfo();
                            amodles.id = amod[i].id;
                            amodles.advContent = amod[i].advContent;
                            a.Update(amodles);
                        }
                        else
                        {
                            Model.advInfo amodles = new Model.advInfo();
                            amodles.id = amod[i].id;
                            amodles.advContent = amod[i].advContent;
                            a.Add(amodles);
                        } 
                    }
                    break;
                case "Areas":
                    List<Model.Areas> Areasmod = new List<Model.Areas>();
                    Areas areasdal = new Areas();
                    //amod = a.GetModelAll();
                    string sqlByAreasModle = "select id,AreaName,AreaNumber from dbo.Areas";
                    cmd = new SqlCommand(sqlByAreasModle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.Areas amodle = new Model.Areas();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.AreaName = dr["AreaName"].ToString();
                        amodle.AreaNumber = dr["AreaNumber"].ToString();
                        Areasmod.Add(amodle);
                    }
                    if (Areasmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < Areasmod.Count; i++)
                    {
                        if (areasdal.Exists(Areasmod[i].id, Areasmod[i].AreaName))
                        {
                            Model.Areas amodles = new Model.Areas();
                            amodles.id = Areasmod[i].id;
                            amodles.AreaName = Areasmod[i].AreaName;
                            amodles.AreaNumber = Areasmod[i].AreaNumber;
                            areasdal.Update(amodles);
                        }
                        else
                        {
                            Model.Areas amodles = new Model.Areas();
                            amodles.id = Areasmod[i].id;
                            amodles.AreaName = Areasmod[i].AreaName;
                            amodles.AreaNumber = Areasmod[i].AreaNumber;
                            areasdal.Add(amodles);
                        } 
                    }
                    break;
                case "billTemplates":

                    List<Model.billTemplates> billTemplatesmod = new List<Model.billTemplates>();
                    billTemplates billTemplatesdal = new billTemplates();
                    //amod = a.GetModelAll();
                    string sqlBybillTemplatesmodle = "select id,name,templates from dbo.billTemplates";
                    cmd = new SqlCommand(sqlBybillTemplatesmodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.billTemplates amodle = new Model.billTemplates();
                        amodle.Id = int.Parse(dr["id"].ToString());
                        amodle.Name = dr["name"].ToString();
                        amodle.Templates1 = dr["templates"].ToString();
                        billTemplatesmod.Add(amodle);
                    }
                    if (billTemplatesmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < billTemplatesmod.Count; i++)
                    {
                        if (billTemplatesdal.Exists(billTemplatesmod[i].Id, billTemplatesmod[i].Name))
                        {
                            Model.billTemplates amodles = new Model.billTemplates();
                            amodles.Id = billTemplatesmod[i].Id;
                            amodles.Name = billTemplatesmod[i].Name;
                            amodles.Templates1 = billTemplatesmod[i].Templates1;
                            billTemplatesdal.Update(amodles);
                        }
                        else
                        {
                            Model.billTemplates amodles = new Model.billTemplates();
                            amodles.Id = billTemplatesmod[i].Id;
                            amodles.Name = billTemplatesmod[i].Name;
                            amodles.Templates1 = billTemplatesmod[i].Templates1;
                            billTemplatesdal.Add(amodles);
                        } 
                    }

                    break;
                //case "birthdayremind":
                //    List<Model.birthdayremind> birthdayremindmod = new List<Model.birthdayremind>();
                //    birthdayremind birthdayreminddal = new birthdayremind();
                //    //amod = a.GetModelAll();
                //    string sqlBybirthdayremindmodle = "select id,remindday,remindcontent,Nowremindcontent,birthdaydiscount from dbo.birthdayremind";
                //    cmd = new SqlCommand(sqlBybirthdayremindmodle, conn);
                //    dr = cmd.ExecuteReader();
                //    while (dr.Read())
                //    {
                //        //Model.birthdayremind amodle = new Model.birthdayremind();
                //        //amodle.Id = int.Parse(dr["id"].ToString());
                //        //amodle.Remindday = int.Parse(dr["remindday"].ToString());
                //        //amodle.Remindcontent = dr["remindcontent"].ToString();
                //        //amodle.Nowremindcontent1 = dr["Nowremindcontent"].ToString();
                //        //amodle.Birthdaydiscount = dr["birthdaydiscount"].ToString();

                //        //birthdayremindmod.Add(amodle);
                //    }
                //    if (birthdayremindmod.Count <= 0)
                //    {
                //        break;
                //    }
                //    for (int i = 0; i < birthdayremindmod.Count; i++)
                //    {
                //        if (birthdayreminddal.Exists(birthdayremindmod[i].Id))
                //        {
                //            Model.birthdayremind amodles = new Model.birthdayremind();
                //            amodles.Id = birthdayremindmod[i].Id;
                //            amodles.Remindday = birthdayremindmod[i].Remindday;
                //            amodles.Nowremindcontent1 = birthdayremindmod[i].Remindcontent;
                //            amodles.Birthdaydiscount = birthdayremindmod[i].Remindcontent;
                //            amodles.Remindcontent = birthdayremindmod[i].Remindcontent;
                           

                //            birthdayreminddal.Update(amodles);
                //        }
                //        else
                //        {
                //            Model.birthdayremind amodles = new Model.birthdayremind();
                //            amodles.Id = birthdayremindmod[i].Id;
                //            amodles.Remindday = birthdayremindmod[i].Remindday;
                //            amodles.Nowremindcontent1 = birthdayremindmod[i].Remindcontent;
                //            amodles.Birthdaydiscount = birthdayremindmod[i].Remindcontent;
                //            amodles.Remindcontent = birthdayremindmod[i].Remindcontent;
                           
                //            birthdayreminddal.add(amodles);
                //        } 
                //    }


                //    break;
                //case "cardTemplates":
                //    List<Model.cardTemplates> cardTemplatesmod = new List<Model.cardTemplates>();
                //    cardTemplates cardTemplatesdal = new cardTemplates();
                //    //amod = a.GetModelAll();
                //    string sqlBycardTemplatesmodle = "select id,name,template from dbo.cardTemplates";
                //    cmd = new SqlCommand(sqlBycardTemplatesmodle, conn);
                //    dr = cmd.ExecuteReader();
                //    while (dr.Read())
                //    {
                //        Model.cardTemplates amodle = new Model.cardTemplates();
                //        amodle.id = int.Parse(dr["id"].ToString());
                //        amodle.name = dr["name"].ToString();
                //        amodle.template = dr["template"].ToString();
                       

                //        cardTemplatesmod.Add(amodle);
                //    }
                //    if (cardTemplatesmod.Count <= 0)
                //    {
                //        break;
                //    }
                //    for (int i = 0; i < cardTemplatesmod.Count; i++)
                //    {
                //        if (cardTemplatesdal.Exists(cardTemplatesmod[i].id, cardTemplatesmod[i].name))
                //        {
                //            Model.cardTemplates amodles = new Model.cardTemplates();
                //            amodles.id = cardTemplatesmod[i].id;
                //            amodles.name = cardTemplatesmod[i].name;
                //            amodles.template = cardTemplatesmod[i].template;
                //            cardTemplatesdal.Update(amodles);
                //        }
                //        else
                //        {
                //            Model.cardTemplates amodles = new Model.cardTemplates();
                //            amodles.id = cardTemplatesmod[i].id;
                //            amodles.name = cardTemplatesmod[i].name;
                //            amodles.template = cardTemplatesmod[i].template;
                //            cardTemplatesdal.Add(amodles);
                //        } 
                //    }

                //    break;
                //case "consumeSolution":
                //    List<Model.consumeSolution> consumeSolutionmod = new List<Model.consumeSolution>();
                //    consumeSolution consumeSolutiondal = new consumeSolution();
                //    //amod = a.GetModelAll();
                //    string sqlByconsumeSolutionmodle = "select id,solutionName,cardTemplateId,consumeSolution1,savingSolution,discountSolution,nextLevelId,levelUp,integralday from dbo.consumeSolution";
                //    cmd = new SqlCommand(sqlByconsumeSolutionmodle, conn);
                //    dr = cmd.ExecuteReader();
                //    while (dr.Read())
                //    {
                //        Model.consumeSolution amodle = new Model.consumeSolution();
                //        amodle.id = int.Parse(dr["id"].ToString());
                //        amodle.solutionName = dr["solutionName"].ToString();
                //        amodle.cardTemplateId = int.Parse(dr["cardTemplateId"].ToString());
                //        amodle.consumeSolution1 = dr["consumeSolution1"].ToString();
                //        amodle.savingSolution = dr["savingSolution"].ToString();
                //        amodle.discountSolution = dr["discountSolution"].ToString();
                //        amodle.nextLevelId = int.Parse(dr["nextLevelId"].ToString());
                //        amodle.levelUp = decimal.Parse(dr["levelUp"].ToString());
                //        amodle.Integralday = int.Parse(dr["integralday"].ToString());
                       

                //        consumeSolutionmod.Add(amodle);
                //    }
                //    if (consumeSolutionmod.Count <= 0)
                //    {
                //        break;
                //    }
                //    for (int i = 0; i < consumeSolutionmod.Count; i++)
                //    {
                //        if (consumeSolutiondal.Exists(consumeSolutionmod[i].id, consumeSolutionmod[i].solutionName))
                //        {
                //            Model.consumeSolution amodles = new Model.consumeSolution();
                //            amodles.id = consumeSolutionmod[i].id;
                //            amodles.solutionName = consumeSolutionmod[i].solutionName;
                //            amodles.cardTemplateId = consumeSolutionmod[i].cardTemplateId;
                //            amodles.consumeSolution1 = consumeSolutionmod[i].consumeSolution1;
                //            amodles.savingSolution = consumeSolutionmod[i].savingSolution;
                //            amodles.discountSolution = consumeSolutionmod[i].discountSolution;
                //            amodles.nextLevelId = consumeSolutionmod[i].nextLevelId;
                //            amodles.levelUp = consumeSolutionmod[i].levelUp;
                //            amodles.Integralday = consumeSolutionmod[i].Integralday;



                //            consumeSolutiondal.Update(amodles);
                //        }
                //        else
                //        {
                //            Model.consumeSolution amodles = new Model.consumeSolution();
                //            amodles.id = consumeSolutionmod[i].id;
                //            amodles.solutionName = consumeSolutionmod[i].solutionName;
                //            amodles.cardTemplateId = consumeSolutionmod[i].cardTemplateId;
                //            amodles.consumeSolution1 = consumeSolutionmod[i].consumeSolution1;
                //            amodles.savingSolution = consumeSolutionmod[i].savingSolution;
                //            amodles.discountSolution = consumeSolutionmod[i].discountSolution;
                //            amodles.nextLevelId = consumeSolutionmod[i].nextLevelId;
                //            amodles.levelUp = consumeSolutionmod[i].levelUp;
                //            amodles.Integralday = consumeSolutionmod[i].Integralday;
                //            consumeSolutiondal.Add(amodles);
                //        } 
                //    }


                //    break;
                case "foregrounding":
                    //List<Model.giftExchangeNotes> giftExchangeNotesmod = new List<Model.giftExchangeNotes>();
                    //giftExchangeNotes giftExchangeNotesdal = new giftExchangeNotes();
                    ////amod = a.GetModelAll();
                    //string sqlBygiftExchangeNotesmodle = "select id,solutionName,cardTemplateId,giftExchangeNotes1,savingSolution,discountSolution,nextLevelId,levelUp,integralday from dbo.giftExchangeNotes";
                    //cmd = new SqlCommand(sqlBygiftExchangeNotesmodle, conn);
                    //dr = cmd.ExecuteReader();
                    //while (dr.Read())
                    //{
                    //    Model.giftExchangeNotes amodle = new Model.giftExchangeNotes();
                    //    amodle.id = int.Parse(dr["id"].ToString());
                    //    amodle.solutionName = dr["solutionName"].ToString();
                    //    amodle.cardTemplateId = int.Parse(dr["cardTemplateId"].ToString());
                    //    amodle.giftExchangeNotes1 = dr["giftExchangeNotes1"].ToString();
                    //    amodle.savingSolution = dr["savingSolution"].ToString();
                    //    amodle.discountSolution = dr["discountSolution"].ToString();
                    //    amodle.nextLevelId = int.Parse(dr["nextLevelId"].ToString());
                    //    amodle.levelUp = decimal.Parse(dr["levelUp"].ToString());
                    //    amodle.Integralday = int.Parse(dr["integralday"].ToString());
                       

                    //    giftExchangeNotesmod.Add(amodle);
                    //}
                    //if (giftExchangeNotesmod.Count <= 0)
                    //{
                    //    break;
                    //}
                    //for (int i = 0; i < giftExchangeNotesmod.Count; i++)
                    //{
                    //    if (giftExchangeNotesdal.Exists(giftExchangeNotesmod[i].id, giftExchangeNotesmod[i].solutionName))
                    //    {
                    //        Model.giftExchangeNotes amodles = new Model.giftExchangeNotes();
                    //        amodles.id = giftExchangeNotesmod[i].id;
                    //        amodles.solutionName = giftExchangeNotesmod[i].solutionName;
                    //        amodles.cardTemplateId = giftExchangeNotesmod[i].cardTemplateId;
                    //        amodles.giftExchangeNotes1 = giftExchangeNotesmod[i].giftExchangeNotes1;
                    //        amodles.savingSolution = giftExchangeNotesmod[i].savingSolution;
                    //        amodles.discountSolution = giftExchangeNotesmod[i].discountSolution;
                    //        amodles.nextLevelId = giftExchangeNotesmod[i].nextLevelId;
                    //        amodles.levelUp = giftExchangeNotesmod[i].levelUp;
                    //        amodles.Integralday = giftExchangeNotesmod[i].Integralday;



                    //        giftExchangeNotesdal.Update(amodles);
                    //    }
                    //    else
                    //    {
                    //        Model.giftExchangeNotes amodles = new Model.giftExchangeNotes();
                    //        amodles.id = giftExchangeNotesmod[i].id;
                    //        amodles.solutionName = giftExchangeNotesmod[i].solutionName;
                    //        amodles.cardTemplateId = giftExchangeNotesmod[i].cardTemplateId;
                    //        amodles.giftExchangeNotes1 = giftExchangeNotesmod[i].giftExchangeNotes1;
                    //        amodles.savingSolution = giftExchangeNotesmod[i].savingSolution;
                    //        amodles.discountSolution = giftExchangeNotesmod[i].discountSolution;
                    //        amodles.nextLevelId = giftExchangeNotesmod[i].nextLevelId;
                    //        amodles.levelUp = giftExchangeNotesmod[i].levelUp;
                    //        amodles.Integralday = giftExchangeNotesmod[i].Integralday;
                    //        giftExchangeNotesdal.Add(amodles);
                    //    } 
                    //}


                    break;
                //case "giftAmount":
                //    List<Model.giftAmount> giftAmountmod = new List<Model.giftAmount>();
                //    giftAmount giftAmountdal = new giftAmount();
                //    //amod = a.GetModelAll();
                //    string sqlBygiftAmountmodle = "select id,giftId,giftName,giftAmount1 from dbo.giftAmount";
                //    cmd = new SqlCommand(sqlBygiftAmountmodle, conn);
                //    dr = cmd.ExecuteReader();
                //    while (dr.Read())
                //    {
                //        Model.giftAmount amodle = new Model.giftAmount();
                //        amodle.id = int.Parse(dr["id"].ToString());
                //        amodle.giftId = int.Parse(dr["giftId"].ToString());
                //        amodle.giftName = dr["giftName"].ToString();
                //        amodle.giftAmount1 = int.Parse(dr["giftAmount1"].ToString());
                //        giftAmountmod.Add(amodle);
                //    }
                //    if (giftAmountmod.Count <= 0)
                //    {
                //        break;
                //    }
                //    for (int i = 0; i < giftAmountmod.Count; i++)
                //    {
                //        if (giftAmountdal.Exists((int)giftAmountmod[i].giftId, giftAmountmod[i].giftName))
                //        {
                //            Model.giftAmount amodles = new Model.giftAmount();
                //            amodles.id = giftAmountmod[i].id;
                //            amodles.giftId = giftAmountmod[i].giftId;
                //            amodles.giftName = giftAmountmod[i].giftName;
                //            amodles.giftAmount1 = giftAmountmod[i].giftAmount1;
                //            giftAmountdal.Update(amodles);
                //        }
                //        else
                //        {
                //            Model.giftAmount amodles = new Model.giftAmount();
                //            amodles.id = giftAmountmod[i].id;
                //            amodles.giftId = giftAmountmod[i].giftId;
                //            amodles.giftName = giftAmountmod[i].giftName;
                //            amodles.giftAmount1 = giftAmountmod[i].giftAmount1;
                //            giftAmountdal.Add(amodles);
                //        } 
                //    }

                //    break;
                case "giftExchangeNotes":
                    List<Model.giftExchangeNotes> giftExchangeNotesmod = new List<Model.giftExchangeNotes>();
                    giftExchangeNotes giftExchangeNotesdal = new giftExchangeNotes();
                    //amod = a.GetModelAll();
                    string sqlBygiftExchangeNotesmodle = "select id,giftId,giftName,giftAmount,integral,date,memo,memberId from dbo.giftExchangeNotes";
                    cmd = new SqlCommand(sqlBygiftExchangeNotesmodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.giftExchangeNotes amodle = new Model.giftExchangeNotes();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.giftId = int.Parse(dr["giftId"].ToString());
                        amodle.giftName = dr["giftName"].ToString();
                        amodle.giftAmount = int.Parse(dr["giftAmount"].ToString());
                        amodle.integral = int.Parse(dr["integral"].ToString());
                        amodle.date = DateTime.Parse(dr["date"].ToString());
                        amodle.memo = dr["memo"].ToString();
                        amodle.memberId = dr["memberId"].ToString();


                        giftExchangeNotesmod.Add(amodle);
                    }
                    if (giftExchangeNotesmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < giftExchangeNotesmod.Count; i++)
                    {
                        if (giftExchangeNotesdal.Exists((int)giftExchangeNotesmod[i].giftId, giftExchangeNotesmod[i].giftName))
                        {
                            Model.giftExchangeNotes amodles = new Model.giftExchangeNotes();
                            amodles.id = giftExchangeNotesmod[i].id;
                            amodles.giftId = giftExchangeNotesmod[i].giftId;
                            amodles.giftName = giftExchangeNotesmod[i].giftName;
                            amodles.giftAmount = giftExchangeNotesmod[i].giftAmount;
                            amodles.integral = giftExchangeNotesmod[i].integral;
                            amodles.date = giftExchangeNotesmod[i].date;
                            amodles.memo = giftExchangeNotesmod[i].memo;
                            amodles.memberId = giftExchangeNotesmod[i].memberId;



                            giftExchangeNotesdal.Update(amodles);
                        }
                        else
                        {
                            Model.giftExchangeNotes amodles = new Model.giftExchangeNotes();
                            amodles.id = giftExchangeNotesmod[i].id;
                            amodles.giftId = giftExchangeNotesmod[i].giftId;
                            amodles.giftName = giftExchangeNotesmod[i].giftName;
                            amodles.giftAmount = giftExchangeNotesmod[i].giftAmount;
                            amodles.integral = giftExchangeNotesmod[i].integral;
                            amodles.date = giftExchangeNotesmod[i].date;
                            amodles.memo = giftExchangeNotesmod[i].memo;
                            amodles.memberId = giftExchangeNotesmod[i].memberId;
                            giftExchangeNotesdal.Add(amodles);
                        } 
                    }


                    break;
                case "gifts":
                    List<Model.gifts> giftsmod = new List<Model.gifts>();
                    gifts giftsdal = new gifts();
                    //amod = a.GetModelAll();
                    string sqlBygiftsmodle = "select id,giftName,type,giftamount,Integral,unit,memo from dbo.gifts";
                    cmd = new SqlCommand(sqlBygiftsmodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.gifts amodle = new Model.gifts();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.giftName = dr["giftName"].ToString();
                        amodle.type = dr["type"].ToString();
                        amodle.giftamount = int.Parse(dr["giftamount"].ToString());
                        amodle.Integral = int.Parse(dr["Integral"].ToString());
                        amodle.unit = dr["unit"].ToString();
                        amodle.memo = dr["memo"].ToString();


                        giftsmod.Add(amodle);
                    }
                    if (giftsmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < giftsmod.Count; i++)
                    {
                        if (giftsdal.Exists(giftsmod[i].id, giftsmod[i].giftName))
                        {
                            Model.gifts amodles = new Model.gifts();
                            amodles.id = giftsmod[i].id;

                            amodles.giftName = giftsmod[i].giftName;
                            amodles.type = giftsmod[i].type;
                            amodles.giftamount = giftsmod[i].giftamount;
                            amodles.Integral = giftsmod[i].Integral;
                            amodles.unit = giftsmod[i].unit;
                            amodles.memo = giftsmod[i].memo;



                            giftsdal.Update(amodles);
                        }
                        else
                        {
                            Model.gifts amodles = new Model.gifts();
                            amodles.id = giftsmod[i].id;
                            amodles.giftName = giftsmod[i].giftName;
                            amodles.type = giftsmod[i].type;
                            amodles.giftamount = giftsmod[i].giftamount;
                            amodles.Integral = giftsmod[i].Integral;
                            amodles.unit = giftsmod[i].unit;
                            amodles.memo = giftsmod[i].memo;
                            giftsdal.Add(amodles);
                        } 
                    }


                    break;
                case "giftsSaved":
                    List<Model.giftsSaved> giftsSavedmod = new List<Model.giftsSaved>();
                    giftsSaved giftsSaveddal = new giftsSaved();
                    //amod = a.GetModelAll();
                    string sqlBygiftsSavedmodle = "select id,giftId,giftName,giftamount from dbo.giftsSaved";
                    cmd = new SqlCommand(sqlBygiftsSavedmodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.giftsSaved amodle = new Model.giftsSaved();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.giftId = int.Parse(dr["giftId"].ToString());
                        amodle.giftName = dr["giftName"].ToString();
                        amodle.giftamount = dr["giftAmount"].ToString();


                        giftsSavedmod.Add(amodle);
                    }
                    if (giftsSavedmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < giftsSavedmod.Count; i++)
                    {
                        if (giftsSaveddal.Exists((int)giftsSavedmod[i].giftId, giftsSavedmod[i].giftName))
                        {
                            Model.giftsSaved amodles = new Model.giftsSaved();
                            amodles.id = giftsSavedmod[i].id;
                            amodles.giftId = giftsSavedmod[i].giftId;
                            amodles.giftName = giftsSavedmod[i].giftName;
                            amodles.giftamount = giftsSavedmod[i].giftamount;



                            giftsSaveddal.Update(amodles);
                        }
                        else
                        {
                            Model.giftsSaved amodles = new Model.giftsSaved();
                            amodles.id = giftsSavedmod[i].id;
                            amodles.giftId = giftsSavedmod[i].giftId;
                            amodles.giftName = giftsSavedmod[i].giftName;
                            amodles.giftamount = giftsSavedmod[i].giftamount;
                            giftsSaveddal.Add(amodles);
                        } 
                    }
                    break;
                case "goods":
                    List<Model.goods> goodsmod = new List<Model.goods>();
                    goods goodsdal = new goods();
                    //amod = a.GetModelAll();
                    string sqlBygoodsmodle = "select id,goodsId,goodsName,unit,price,Promotionprice,Promotion,goodsTypeId,amount from dbo.goods";
                    cmd = new SqlCommand(sqlBygoodsmodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.goods amodle = new Model.goods();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.goodsId = dr["goodsId"].ToString();
                        amodle.goodsName = dr["goodsName"].ToString();
                        amodle.unit = dr["unit"].ToString();
                        amodle.price = decimal.Parse(dr["price"].ToString());
                        amodle.Promotionprice = dr["Promotionprice"].ToString();

                        amodle.Promotion = Convert.ToBoolean(dr["Promotion"]);

                        amodle.goodsTypeId =dr["goodsTypeId"].ToString();
                        amodle.amount = Convert.ToInt32( dr["lowestOff"]);
                        



                        goodsmod.Add(amodle);
                    }
                    if (goodsmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < goodsmod.Count; i++)
                    {
                        if (goodsdal.Exists(int.Parse(goodsmod[i].goodsId), goodsmod[i].goodsName))
                        {
                            Model.goods amodles = new Model.goods();
                            amodles.id = goodsmod[i].id;
                            amodles.goodsId = goodsmod[i].goodsId;
                            amodles.goodsName = goodsmod[i].goodsName;
                            amodles.unit = goodsmod[i].unit;
                            amodles.price = goodsmod[i].price;
                            amodles.Promotionprice = goodsmod[i].Promotionprice;
                            amodles.Promotion = goodsmod[i].Promotion;
                            amodles.goodsTypeId = goodsmod[i].goodsTypeId;
                            amodles.amount = goodsmod[i].amount;
                            //amodles.Golddiscount = goodsmod[i].Golddiscount;
                            //amodles.Silverdiscount = goodsmod[i].Silverdiscount;


                            goodsdal.Update(amodles);
                        }
                        else
                        {
                            Model.goods amodles = new Model.goods();
                            amodles.id = goodsmod[i].id;
                            amodles.goodsId = goodsmod[i].goodsId;
                            amodles.goodsName = goodsmod[i].goodsName;
                            amodles.unit = goodsmod[i].unit;
                            amodles.price = goodsmod[i].price;
                            amodles.Promotionprice = goodsmod[i].Promotionprice;
                            amodles.Promotion = goodsmod[i].Promotion;
                            amodles.goodsTypeId = goodsmod[i].goodsTypeId;
                            amodles.amount = goodsmod[i].amount;
                            amodles.goodsTypeId = goodsmod[i].goodsTypeId;
                            //amodles.Golddiscount = goodsmod[i].Golddiscount;
                            //amodles.Silverdiscount = goodsmod[i].Silverdiscount;
                            goodsdal.Add(amodles);
                        }
                    }

                    break;
                case "goodsflowing":
                    List<Model.goodsflowing> goodsflowingmod = new List<Model.goodsflowing>();
                    goodsflowing goodsflowingdal = new goodsflowing();
                    //amod = a.GetModelAll();
                    string sqlBygoodsflowingmodle = "select id,username,Time,operate,goodsId,goodsName,unit,price,Promotion,Promotionprice,goodsTypeId from dbo.goodsflowing";
                    cmd = new SqlCommand(sqlBygoodsflowingmodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.goodsflowing amodle = new Model.goodsflowing();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.username = dr["username"].ToString();
                        amodle.Time = DateTime.Parse(dr["Time"].ToString());
                        amodle.operate = dr["operate"].ToString();
                        amodle.goodsId = dr["goodsId"].ToString();
                        amodle.goodsName = dr["goodsName"].ToString();
                        amodle.unit = dr["unit"].ToString();
                        amodle.price = decimal.Parse(dr["price"].ToString());
                        amodle.Promotionprice =dr["Promotionprice"].ToString();
                        amodle.goodsTypeId = dr["goodsTypeId"].ToString();
                        

                        goodsflowingmod.Add(amodle);
                    }
                    if (goodsflowingmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < goodsflowingmod.Count; i++)
                    {
                        if (goodsflowingdal.Exists(goodsflowingmod[i].id, goodsflowingmod[i].goodsId))
                        {
                            Model.goodsflowing amodles = new Model.goodsflowing();
                            amodles.id = goodsflowingmod[i].id;
                            amodles.username = goodsflowingmod[i].username;
                            amodles.Time = goodsflowingmod[i].Time;
                            amodles.operate = goodsflowingmod[i].unit;
                            amodles.goodsId = goodsflowingmod[i].goodsId;
                            amodles.goodsName = goodsflowingmod[i].goodsName;
                            amodles.unit = goodsflowingmod[i].unit;
                            amodles.price = goodsflowingmod[i].price;
                            amodles.Promotionprice = goodsflowingmod[i].Promotionprice;
                            amodles.goodsTypeId = goodsflowingmod[i].goodsTypeId;
                            goodsflowingdal.Update(amodles);
                        }
                        else
                        {
                            Model.goodsflowing amodles = new Model.goodsflowing();
                            amodles.id = goodsflowingmod[i].id;
                            amodles.username = goodsflowingmod[i].username;
                            amodles.Time = goodsflowingmod[i].Time;
                            amodles.operate = goodsflowingmod[i].unit;
                            amodles.goodsId = goodsflowingmod[i].goodsId;
                            amodles.goodsName = goodsflowingmod[i].goodsName;
                            amodles.unit = goodsflowingmod[i].unit;
                            amodles.price = goodsflowingmod[i].price;
                            amodles.Promotionprice = goodsflowingmod[i].Promotionprice;
                            amodles.goodsTypeId = goodsflowingmod[i].goodsTypeId;
                            goodsflowingdal.Add(amodles);
                        } 
                    }

                    break;
                case "goodsInfo":
                    List<Model.goodsInfo> goodsInfomod = new List<Model.goodsInfo>();
                    goodsInfo goodsInfodal = new goodsInfo();
                    //amod = a.GetModelAll();
                    string sqlBygoodsInfomodle = "select id,gid,goodscount,goodsprice,selltime,zhekou,wasteBookId from dbo.goodsInfo";
                    cmd = new SqlCommand(sqlBygoodsInfomodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.goodsInfo amodle = new Model.goodsInfo();
                        amodle.Id = int.Parse(dr["id"].ToString());
                        amodle.Gid = dr["gid"].ToString();
                        amodle.Goodscount = int.Parse(dr["goodscount"].ToString());
                        amodle.Goodsprice = decimal.Parse(dr["goodsprice"].ToString());
                        amodle.Selltime = dr["selltime"].ToString();
                        amodle.Zhekou = dr["zhekou"].ToString();
                        amodle.wasteBookId = int.Parse(dr["wasteBookId"].ToString());
                        goodsInfomod.Add(amodle);
                    }
                    if (goodsInfomod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < goodsInfomod.Count; i++)
                    {
                        if (goodsInfodal.Exists(goodsInfomod[i].Id, goodsInfomod[i].Gid))
                        {
                            //Model.goodsInfo amodles = new Model.goodsInfo();
                            //amodles.Id = goodsInfomod[i].Id;
                            //amodles.Gid = goodsInfomod[i].Gid;
                            //amodles.Goodscount = goodsInfomod[i].Goodscount;
                            //amodles.Goodsprice = goodsInfomod[i].Goodsprice;
                            //amodles.Selltime = goodsInfomod[i].Selltime;
                            //amodles.Zhekou = goodsInfomod[i].Zhekou;
                            //amodles.wasteBookId = goodsInfomod[i].wasteBookId;

                            //goodsInfodal.Update(amodles);
                        }
                        else
                        {
                            Model.goodsInfo amodles = new Model.goodsInfo();
                            amodles.Id = goodsInfomod[i].Id;
                            amodles.Gid = goodsInfomod[i].Gid;
                            amodles.Goodscount = goodsInfomod[i].Goodscount;
                            amodles.Goodsprice = goodsInfomod[i].Goodsprice;
                            amodles.Selltime = goodsInfomod[i].Selltime;
                            amodles.Zhekou = goodsInfomod[i].Zhekou;
                            amodles.wasteBookId = goodsInfomod[i].wasteBookId;
                            
                            goodsInfodal.add(amodles);
                        } 
                    }
                    break;
                case "goodsType":
                    List<Model.goodsType> goodsTypemod = new List<Model.goodsType>();
                    goodsType goodsTypedal = new goodsType();
                    //amod = a.GetModelAll();
                    string sqlBygoodsTypemodle = "select id,typeName from dbo.goodsType";
                    cmd = new SqlCommand(sqlBygoodsTypemodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.goodsType amodle = new Model.goodsType();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.typeName = dr["typeName"].ToString();
                        goodsTypemod.Add(amodle);
                    }
                    if (goodsTypemod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < goodsTypemod.Count; i++)
                    {
                        if (goodsTypedal.Exists(goodsTypemod[i].typeName))
                        {
                            Model.goodsType amodles = new Model.goodsType();
                            amodles.id = goodsTypemod[i].id;
                            amodles.typeName = goodsTypemod[i].typeName;
                            goodsTypedal.Update(amodles);
                        }
                        else
                        {
                            Model.goodsType amodles = new Model.goodsType();
                            amodles.id = goodsTypemod[i].id;
                            amodles.typeName = goodsTypemod[i].typeName;
                            goodsTypedal.Add(amodles);
                        } 
                    }

                    break;
                case "informationShare":

                    break;
                case "memberInfo":
                    List<Model.memberInfo> memberInfomod = new List<Model.memberInfo>();
                    memberInfo memberInfodal = new memberInfo();
                    //amod = a.GetModelAll();
                    string sqlBymemberInfomodle = "select id,memberId,memberCardId,memberName,sex,mobile,Tel,Email,IDNumber,birthDay,cardType,Balance,point,status,createDate,expiresDate,consume,memo,pwd,Marriage,Zip,Address,AreasID,MemberType,shifouhuixing,tuiguangren from dbo.memberInfo";
                    cmd = new SqlCommand(sqlBymemberInfomodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.memberInfo amodle = new Model.memberInfo();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.memberId = dr["memberId"].ToString();
                        amodle.memberCardId = dr["memberCardId"].ToString();
                        amodle.memberName = dr["memberName"].ToString();
                        amodle.sex = bool.Parse(dr["sex"].ToString());
                        amodle.mobile = dr["mobile"].ToString();
                        amodle.Tel = dr["Tel"].ToString();
                        amodle.Email = dr["Email"].ToString();
                        amodle.IDNumber = dr["IDNumber"].ToString();
                        amodle.birthDay = DateTime.Parse(dr["birthDay"].ToString());
                        amodle.cardType = int.Parse(dr["cardType"].ToString());
                        amodle.Balance = decimal.Parse(dr["Balance"].ToString());
                        amodle.point = int.Parse(dr["point"].ToString());
                        amodle.status = int.Parse(dr["status"].ToString());
                        amodle.createDate = DateTime.Parse(dr["createDate"].ToString());
                        amodle.expiresDate = DateTime.Parse(dr["expiresDate"].ToString());
                        amodle.consume = decimal.Parse(dr["consume"].ToString());
                        amodle.memo = dr["memo"].ToString();
                        amodle.pwd = dr["pwd"].ToString();
                        amodle.Marriage = dr["Marriage"].ToString();
                        amodle.Zip = dr["Zip"].ToString();
                        amodle.Address = dr["Address"].ToString();
                        amodle.AreasID = int.Parse(dr["AreasID"].ToString());
                        amodle.MemberType = dr["MemberType"].ToString();
                        //amodle.Shifoushouxin = dr["shifouhuixing"].ToString();
                        //amodle.Tuiguangren = dr["tuiguangren"].ToString();
                        memberInfomod.Add(amodle);
                    }
                    if (memberInfomod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < memberInfomod.Count; i++)
                    {
                        if (memberInfodal.Exists(memberInfomod[i].memberId, memberInfomod[i].memberCardId))
                        {
                            Model.memberInfo amodles = new Model.memberInfo();
                            amodles.id = memberInfomod[i].id;
                            amodles.memberId = memberInfomod[i].memberId;
                            amodles.memberCardId = memberInfomod[i].memberCardId;
                            amodles.memberName = memberInfomod[i].memberName;
                            amodles.sex = memberInfomod[i].sex;
                            amodles.mobile = memberInfomod[i].mobile;
                            amodles.Tel = memberInfomod[i].Tel;
                            amodles.Email = memberInfomod[i].Email;
                            amodles.IDNumber = memberInfomod[i].IDNumber;
                            amodles.birthDay = memberInfomod[i].birthDay;
                            amodles.cardType = memberInfomod[i].cardType;
                            amodles.Balance = memberInfomod[i].Balance;
                            amodles.point = memberInfomod[i].point;
                            amodles.status = memberInfomod[i].status;
                            amodles.createDate = memberInfomod[i].createDate;
                            amodles.expiresDate = memberInfomod[i].expiresDate;
                            amodles.consume = memberInfomod[i].consume;
                            amodles.memo = memberInfomod[i].memo;
                            amodles.pwd = memberInfomod[i].pwd;
                            amodles.Marriage = memberInfomod[i].Marriage;
                            amodles.Zip = memberInfomod[i].Zip;
                            amodles.Address = memberInfomod[i].Address;
                            amodles.AreasID = memberInfomod[i].AreasID;
                            amodles.MemberType = memberInfomod[i].MemberType;
             

                            memberInfodal.Update(amodles);
                        }
                        else
                        {
                            Model.memberInfo amodles = new Model.memberInfo();
                            amodles.id = memberInfomod[i].id;
                            amodles.memberId = memberInfomod[i].memberId;
                            amodles.memberCardId = memberInfomod[i].memberCardId;
                            amodles.memberName = memberInfomod[i].memberName;
                            amodles.sex = memberInfomod[i].sex;
                            amodles.mobile = memberInfomod[i].mobile;
                            amodles.Tel = memberInfomod[i].Tel;
                            amodles.Email = memberInfomod[i].Email;
                            amodles.IDNumber = memberInfomod[i].IDNumber;
                            amodles.birthDay = memberInfomod[i].birthDay;
                            amodles.cardType = memberInfomod[i].cardType;
                            amodles.Balance = memberInfomod[i].Balance;
                            amodles.point = memberInfomod[i].point;
                            amodles.status = memberInfomod[i].status;
                            amodles.createDate = memberInfomod[i].createDate;
                            amodles.expiresDate = memberInfomod[i].expiresDate;
                            amodles.consume = memberInfomod[i].consume;
                            amodles.memo = memberInfomod[i].memo;
                            amodles.pwd = memberInfomod[i].pwd;
                            amodles.Marriage = memberInfomod[i].Marriage;
                            amodles.Zip = memberInfomod[i].Zip;
                            amodles.Address = memberInfomod[i].Address;
                            amodles.AreasID = memberInfomod[i].AreasID;
                            amodles.MemberType = memberInfomod[i].MemberType;
                            amodles.Profession = memberInfomod[i].Profession;
                            amodles.hobby = memberInfomod[i].hobby;
                            amodles.QQ = memberInfomod[i].QQ;
                            amodles.Child = memberInfomod[i].Child;
                            amodles.Unit = memberInfomod[i].Unit;
                            amodles.OpenTeacher = memberInfomod[i].OpenTeacher;
                            memberInfodal.Add(amodles);
                            
                        } 
                    }



                    break;
                //case "MoneyStyle":
                //    List<Model.MoneyStyle> MoneyStylemod = new List<Model.MoneyStyle>();
                //    MoneyStyle MoneyStyledal = new MoneyStyle();
                //    //amod = a.GetModelAll();
                //    string sqlByMoneyStylemodle = "select id,typeName from dbo.MoneyStyle";
                //    cmd = new SqlCommand(sqlByMoneyStylemodle, conn);
                //    dr = cmd.ExecuteReader();
                //    while (dr.Read())
                //    {
                //        Model.MoneyStyle amodle = new Model.MoneyStyle();
                //        amodle.id = int.Parse(dr["id"].ToString());
                //        amodle.typeName = dr["typeName"].ToString();
                //        MoneyStylemod.Add(amodle);
                //    }
                //    if (MoneyStylemod.Count <= 0)
                //    {
                //        break;
                //    }
                //    for (int i = 0; i < MoneyStylemod.Count; i++)
                //    {
                //        if (MoneyStyledal.Exists(MoneyStylemod[i].typeName))
                //        {
                //            Model.MoneyStyle amodles = new Model.MoneyStyle();
                //            amodles.id = MoneyStylemod[i].id;
                //            amodles.typeName = MoneyStylemod[i].typeName;
                //            MoneyStyledal.Update(amodles);
                //        }
                //        else
                //        {
                //            Model.MoneyStyle amodles = new Model.MoneyStyle();
                //            amodles.id = MoneyStylemod[i].id;
                //            amodles.typeName = MoneyStylemod[i].typeName;
                //            MoneyStyledal.Add(amodles);
                //        } 
                //    }


                //    break;
                case "operatorInfo":

                    List<Model.operatorInfo> operatorInfomod = new List<Model.operatorInfo>();
                    operatorInfo operatorInfodal = new operatorInfo();
                    //amod = a.GetModelAll();
                    string sqlByoperatorInfomodle = "select id,username,password,name,sex,phone,roleId from dbo.operatorInfo";
                    cmd = new SqlCommand(sqlByoperatorInfomodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.operatorInfo amodle = new Model.operatorInfo();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.username = dr["username"].ToString();
                        amodle.password = dr["password"].ToString();
                        amodle.name = dr["name"].ToString();
                        amodle.sex =bool.Parse(dr["sex"].ToString());
                        amodle.phone = dr["phone"].ToString();
                        amodle.roleId = int.Parse(dr["roleId"].ToString());
                        
                        operatorInfomod.Add(amodle);
                    }
                    if (operatorInfomod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < operatorInfomod.Count; i++)
                    {
                        if (operatorInfodal.Exists(operatorInfomod[i].username, operatorInfomod[i].name))
                        {
                            Model.operatorInfo amodles = new Model.operatorInfo();
                            amodles.id = operatorInfomod[i].id;
                            amodles.username = operatorInfomod[i].username;
                            amodles.password = operatorInfomod[i].password;
                            amodles.name = operatorInfomod[i].name;
                            amodles.sex = operatorInfomod[i].sex;
                            amodles.phone = operatorInfomod[i].phone;
                            amodles.roleId = operatorInfomod[i].roleId;
                            
                            operatorInfodal.Update(amodles);
                        }
                        else
                        {
                            Model.operatorInfo amodles = new Model.operatorInfo();
                            amodles.id = operatorInfomod[i].id;
                            amodles.username = operatorInfomod[i].username;
                            amodles.password = operatorInfomod[i].password;
                            amodles.name = operatorInfomod[i].name;
                            amodles.sex = operatorInfomod[i].sex;
                            amodles.phone = operatorInfomod[i].phone;
                            amodles.roleId = operatorInfomod[i].roleId;
                            operatorInfodal.Add(amodles);
                        } 
                    }
                    break;
                case "remind":


                    break;
                case "roleInfo":
                    List<Model.roleInfo> roleInfomod = new List<Model.roleInfo>();
                    roleInfo roleInfodal = new roleInfo();
                    //amod = a.GetModelAll();
                    string sqlByroleInfomodle = "select id,roleInfo1,roleName,specialrebate from dbo.roleInfo";
                    cmd = new SqlCommand(sqlByroleInfomodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.roleInfo amodle = new Model.roleInfo();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.roleInfo1 = dr["roleInfo1"].ToString();
                        amodle.roleName = dr["roleName"].ToString();
                        amodle.Specialrebate = dr["specialrebate"].ToString();
                        
                        roleInfomod.Add(amodle);
                    }
                    if (roleInfomod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < roleInfomod.Count; i++)
                    {
                        if (roleInfodal.Exists(roleInfomod[i].roleName))
                        {
                            //Model.roleInfo amodles = new Model.roleInfo();
                            //amodles.id = roleInfomod[i].id;
                            //amodles.roleInfo1 = roleInfomod[i].roleInfo1;
                            //amodles.roleName = roleInfomod[i].roleName;
                            //amodles.Specialrebate = roleInfomod[i].Specialrebate;
                            
                            
                            //roleInfodal.Update(amodles);
                        }
                        else
                        {
                            Model.roleInfo amodles = new Model.roleInfo();
                            amodles.id = roleInfomod[i].id;
                            amodles.roleInfo1 = roleInfomod[i].roleInfo1;
                            amodles.roleName = roleInfomod[i].roleName;
                            amodles.Specialrebate = roleInfomod[i].Specialrebate;
                            roleInfodal.Add(amodles);
                        } 
                    }


                    break;
                case "systemSettings":
                    

                    break;
                //case "User_Productwater":

                //    List<Model.User_Productwater> User_Productwatermod = new List<Model.User_Productwater>();
                //    User_Productwater User_Productwaterdal = new User_Productwater();
                //    //amod = a.GetModelAll();
                //    string sqlByUser_Productwatermodle = "select id,admin,UserId,ConsDate,CommodityId,Money,Quantity from dbo.User_Productwater";
                //    cmd = new SqlCommand(sqlByUser_Productwatermodle, conn);
                //    dr = cmd.ExecuteReader();
                //    while (dr.Read())
                //    {
                //        Model.User_Productwater amodle = new Model.User_Productwater();
                //        amodle.id = int.Parse(dr["id"].ToString());
                //        amodle.admin = dr["admin"].ToString();
                //        amodle.UserId = dr["UserId"].ToString();
                //        amodle.ConsDate =dr["ConsDate"].ToString();
                //        amodle.CommodityId =int.Parse(dr["CommodityId"].ToString());
                //        amodle.Money = decimal.Parse(dr["Money"].ToString());
                //        amodle.Quantity = int.Parse(dr["Quantity"].ToString());
                //        User_Productwatermod.Add(amodle);
                //    }
                //    if (User_Productwatermod.Count <= 0)
                //    {
                //        break;
                //    }
                //    for (int i = 0; i < User_Productwatermod.Count; i++)
                //    {
                //        if (User_Productwaterdal.Exists(User_Productwatermod[i].UserId, User_Productwatermod[i].ConsDate.ToString()))
                //        {
                //            //Model.User_Productwater amodles = new Model.User_Productwater();
                //            //amodles.id = User_Productwatermod[i].id;
                //            //amodles.admin = User_Productwatermod[i].admin;
                //            //amodles.ConsDate = User_Productwatermod[i].ConsDate;
                //            //amodles.CommodityId = User_Productwatermod[i].CommodityId;
                //            //amodles.Money = User_Productwatermod[i].Money;
                //            //amodles.Quantity = User_Productwatermod[i].Quantity;
                //            //User_Productwaterdal.Update(amodles);
                //        }
                //        else
                //        {
                //            Model.User_Productwater amodles = new Model.User_Productwater();
                //            amodles.id = User_Productwatermod[i].id;
                //            amodles.admin = User_Productwatermod[i].admin;
                //            amodles.ConsDate = User_Productwatermod[i].ConsDate;
                //            amodles.CommodityId = User_Productwatermod[i].CommodityId;
                //            amodles.Money = User_Productwatermod[i].Money;
                //            amodles.Quantity = User_Productwatermod[i].Quantity;
                //            User_Productwaterdal.Add(amodles);
                //        } 
                //    }
                //    break;
             
                case "usersystemnode":

                     List<Model.usersystemnode> usersystemnodemod = new List<Model.usersystemnode>();
                    usersystemnode usersystemnodedal = new usersystemnode();
                    //amod = a.GetModelAll();
                    string sqlByusersystemnodemodle = "select id,username,loginTime,leaveTime from dbo.usersystemnode";
                    cmd = new SqlCommand(sqlByusersystemnodemodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.usersystemnode amodle = new Model.usersystemnode();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.username = dr["username"].ToString();
                        amodle.loginTime =DateTime.Parse(dr["loginTime"].ToString());
                        amodle.leaveTime = DateTime.Parse(dr["leaveTime"].ToString());
                       
                        usersystemnodemod.Add(amodle);
                    }
                    if (usersystemnodemod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < usersystemnodemod.Count; i++)
                    {
                        if (usersystemnodedal.Exists(usersystemnodemod[i].username, usersystemnodemod[i].loginTime.ToString(), usersystemnodemod[i].leaveTime.ToString()))
                        {
                            //Model.usersystemnode amodles = new Model.usersystemnode();
                            //amodles.id = usersystemnodemod[i].id;
                            //amodles.username = usersystemnodemod[i].username;
                            //amodles.loginTime = usersystemnodemod[i].loginTime;
                            //amodles.leaveTime = usersystemnodemod[i].leaveTime;
                           
                            //usersystemnodedal.Update(amodles);
                        }
                        else
                        {
                            Model.usersystemnode amodles = new Model.usersystemnode();
                            amodles.id = usersystemnodemod[i].id;
                            amodles.username = usersystemnodemod[i].username;
                            amodles.loginTime = usersystemnodemod[i].loginTime;
                            amodles.leaveTime = usersystemnodemod[i].leaveTime;
                           
                            usersystemnodedal.Add(amodles);
                        } 
                    }
                    break;
                case "wasteBook":
                    List<Model.wasteBook> wasteBookmod = new List<Model.wasteBook>();
                    wasteBook wasteBookdal = new wasteBook();
                    //amod = a.GetModelAll();
                    string sqlBywasteBookmodle = "select id,terminalId,operatorId,memberCardId,date,consumeType,consumeTimes,consumeMoney,cardPayMoney,cashPayMoney,cardBalance,refundmentMoney,refundmentIntegral,exchangeIntegral,consumeIntegral,totalIntegral,savingMoney,details,Discount from dbo.wasteBook where details = 0";
                    cmd = new SqlCommand(sqlBywasteBookmodle, conn);
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        Model.wasteBook amodle = new Model.wasteBook();
                        amodle.id = int.Parse(dr["id"].ToString());
                        amodle.terminalId = dr["terminalId"].ToString();
                        amodle.operatorId = dr["operatorId"].ToString();
                        amodle.memberCardId = dr["memberCardId"].ToString();
                        amodle.date = DateTime.Parse(dr["date"].ToString());
                        amodle.consumeType = int.Parse(dr["consumeType"].ToString());
                        amodle.consumeTimes = dr["consumeTimes"].ToString();
                        amodle.consumeMoney = decimal.Parse(dr["consumeMoney"].ToString());
                        amodle.cardPayMoney = decimal.Parse(dr["cardPayMoney"].ToString());
                        amodle.cashPayMoney = decimal.Parse(dr["cashPayMoney"].ToString());
                        amodle.cardBalance = decimal.Parse(dr["cardBalance"].ToString());
                        amodle.refundmentMoney = decimal.Parse(dr["refundmentMoney"].ToString());
                        amodle.refundmentIntegral = int.Parse(dr["refundmentIntegral"].ToString());
                        amodle.exchangeIntegral = int.Parse(dr["exchangeIntegral"].ToString());
                        amodle.consumeIntegral = int.Parse(dr["consumeIntegral"].ToString());
                        amodle.totalIntegral = int.Parse(dr["totalIntegral"].ToString());
                        amodle.savingMoney = decimal.Parse(dr["savingMoney"].ToString());
                        amodle.details = "1";
                        amodle.Discount = float.Parse(dr["Discount"].ToString());
                        
                        wasteBookmod.Add(amodle);
                    }
                    dr.Close();
                    if (wasteBookmod.Count <= 0)
                    {
                        break;
                    }
                    for (int i = 0; i < wasteBookmod.Count; i++)
                    {

                        //if (wasteBookdal.Exists())
                        //{

                        //}
                            Model.wasteBook amodles = new Model.wasteBook();
                            amodles.id = wasteBookmod[i].id;
                            amodles.terminalId = wasteBookmod[i].terminalId;
                            amodles.operatorId = wasteBookmod[i].operatorId;
                            amodles.memberCardId = wasteBookmod[i].memberCardId;
                            amodles.date = wasteBookmod[i].date;
                            amodles.consumeType = wasteBookmod[i].consumeType;
                            amodles.consumeTimes = wasteBookmod[i].consumeTimes;
                            amodles.consumeMoney = wasteBookmod[i].consumeMoney;
                            amodles.cardPayMoney = wasteBookmod[i].cardPayMoney;
                            amodles.cashPayMoney = wasteBookmod[i].cashPayMoney;
                            amodles.cardBalance = wasteBookmod[i].cardBalance;
                            amodles.refundmentMoney = wasteBookmod[i].refundmentMoney;
                            amodles.refundmentIntegral = wasteBookmod[i].refundmentIntegral;
                            amodles.exchangeIntegral = wasteBookmod[i].exchangeIntegral;
                            amodles.consumeIntegral = wasteBookmod[i].consumeIntegral;
                            amodles.totalIntegral = wasteBookmod[i].totalIntegral;
                            amodles.savingMoney = wasteBookmod[i].savingMoney;
                            amodles.details = "1";
                            amodles.Discount = wasteBookmod[i].Discount;
                            wasteBookdal.Add(amodles);

                            string sqlll = "update wasteBook set details = '1' where id = " + wasteBookmod[i].id;

                            cmd = new SqlCommand(sqlll, conn);
                            cmd.ExecuteNonQuery();
                            
                            //=================
                            //amodles.id = wasteBookmod[i].id;
                            //amodles.terminalId = wasteBookmod[i].terminalId;
                            //amodles.operatorId = wasteBookmod[i].operatorId;
                            //amodles.memberCardId = wasteBookmod[i].memberCardId;
                            //amodles.date = wasteBookmod[i].date;
                            //amodles.consumeType = wasteBookmod[i].consumeType;
                            //amodles.consumeTimes = wasteBookmod[i].consumeTimes;
                            //amodles.consumeMoney = wasteBookmod[i].consumeMoney;
                            //amodles.cardPayMoney = wasteBookmod[i].cardPayMoney;
                            //amodles.cashPayMoney = wasteBookmod[i].cashPayMoney;
                            //amodles.cardBalance = wasteBookmod[i].cardBalance;
                            //amodles.refundmentMoney = wasteBookmod[i].refundmentMoney;
                            //amodles.refundmentIntegral = wasteBookmod[i].refundmentIntegral;
                            //amodles.exchangeIntegral = wasteBookmod[i].exchangeIntegral;
                            //amodles.consumeIntegral = wasteBookmod[i].consumeIntegral;
                            //amodles.totalIntegral = wasteBookmod[i].totalIntegral;
                            //amodles.savingMoney = wasteBookmod[i].savingMoney;
                            //amodles.details = "1";
                            //amodles.Discount = wasteBookmod[i].Discount;
                            //wasteBookdal.Update(amodles);

                    }


                    break;
                default:
                    break;      
            }
            //dr.Close();
            conn.Close();
        }

    }
}
